// 执行 async 函数，返回的都是 Promise 对象
async function test1(){
  return 1;
}

async function test2(){
  return Promise.resolve(2);
}

const res1 = test1();
const res2 = test2();
console.log("res1:", res1)
console.log("res2:", res2)

// Promise.then 成功的情况对应 await
async function test3(){
  const p3 = Promise.resolve(3);
  p3.then(data3 => {
    console.log("data:", data3)
  })

  const data3 = await p3;
  console.log('await data:', data3);
}
test3();

async function test4(){
  const data4 = await 4; // 等同于 await Promise.resolve(4)
  console.log('data4:', data4)
}
test4();

async function test5(){
  const data5 = await test1();
  console.log('data5:', data5);
}
test5();

// Promise.catch 异常的情况下 对应 try...catch
async function test6(){
  const p6 = Promise.reject(6);
  try{
    const data6 = await p6;
    console.log('data6:', data6)
  }catch(e){
    console.error("error info:", e)
  }
}
test6();
